import type { StaffItem } from '#/views/system/staff/data';

import { requestClient } from '#/api/request';

export namespace StaffApi {
  export interface StaffListParams {
    keyword?: string;
    page: number;
    pageSize: number;
  }

  export interface StaffListResult {
    list: StaffItem[];
    page: number;
    pageSize: number;
    total: number;
  }
}

/**
 * 获取组织职员列表
 */
export async function getStaffList(
  params: StaffApi.StaffListParams,
): Promise<StaffApi.StaffListResult> {
  const response = await requestClient.get<{
    list: StaffItem[];
    page: number;
    pageSize: number;
    total: number;
  }>('/system/staff/list', { params });

  return {
    list: response.list || [],
    page: response.page || 1,
    pageSize: response.pageSize || 20,
    total: response.total || 0,
  };
}

/**
 * 创建组织职员
 */
export async function createStaff(data: Partial<StaffItem>): Promise<void> {
  await requestClient.post('/system/staff', data);
}

/**
 * 更新组织职员
 */
export async function updateStaff(
  id: string,
  data: Partial<StaffItem>,
): Promise<void> {
  await requestClient.put(`/system/staff/${id}`, data);
}

/**
 * 删除组织职员
 */
export async function deleteStaff(id: string): Promise<void> {
  await requestClient.delete(`/system/staff/${id}`);
}